package cn.mylearn.sys.config;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.CaseInsensitiveContainerFactory;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.template.Engine;

import cn.mylearn.sys.controller.login.LoginController;
import cn.mylearn.sys.handler.GlobalHandler;
import cn.mylearn.tools.extdialect.MyOracleDialect;

public class SysConfig extends JFinalConfig {
	/**
	 * 常量配置
	 */
	public void configConstant(Constants me) {
		//加载配置文件
		PropKit.use("db_config.properties");
		me.setEncoding(PropKit.get("Encoding"));
		//文件上传大小
		me.setMaxPostSize(PropKit.getInt("UploadSize"));
		//设置开发模式
		me.setDevMode(PropKit.getBoolean("DevMode"));
	};
	
	/**
	 * 路由配置
	 */
	public void configRoute(Routes me) {
		me.add("/",LoginController.class);
		me.add(new ActionRoutes());
	};
	
	/**
	 * 引擎配置
	 */
	public  void configEngine(Engine me) {
		
	};
	
	/**
	 * 插件配置
	 */
	public void configPlugin(Plugins me) {
		//数据源配置
		DruidPlugin druidPlugin = new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("username"), PropKit.get("password"));
		//驱动设置
		druidPlugin.setDriverClass(PropKit.get("driver"));
		//ActiveRecord
		ActiveRecordPlugin arp = new ActiveRecordPlugin("druidPlugin",druidPlugin);
		//设置数据库方言 重写replaceOrderBy方法
		arp.setDialect(new MyOracleDialect());
		//容器工厂 统一转成小写（配置arp表，id,Model获取值时忽略）
		arp.setContainerFactory(new CaseInsensitiveContainerFactory(true));
		//是否输出sql
		arp.setShowSql(PropKit.getBoolean("ShowSql"));
		//配置表关系映射
		OrmConfig.setTableMappingSys(arp);
		//添加druid插件
		me.add(druidPlugin);
		//添加activerecord插件
		me.add(arp);
	}
	
	/**
	 * 拦截器配置
	 */
	public  void configInterceptor(Interceptors me) {
		
	}
	
	/**
	 * 处理器配置
	 */
	public  void configHandler(Handlers me) {
		me.add(new GlobalHandler());
	}
	
	

}
